package 类和对象课堂练习.封装;

import 类和对象课堂练习.Eyu;
import 类和对象课堂练习.Pet;

public class Master {
    private String name;

    public Master(String name) {
        this.name = name;
    }

    public void print(Pet b) {
        for (; ; ) {
            if (b.getHealth() < 100) {
                System.out.println(name + "给"+b.getName()+"喂食物");
                b.setHealth(b.getHealth() + 10);
                if (b.getHealth()>=100){
                    b.setHealth(100);
                }
                if (b instanceof Dog){
                    ((Dog)b).print();//强转
                    System.out.println("狗狗会玩接飞盘游戏");
                }
                else if (b instanceof Eyu){
                    ((Eyu)b).print();
                    System.out.println("鳄鱼会玩吃人游戏");
                }else if (b instanceof Hamster){
                    ((Hamster)b).print();
                    System.out.println("仓鼠喜欢啃桌腿");
                }
                System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
            }
            else if (b.getHealth() >=100){
                break;
            }
        }
    }
}
